/**
 * Created by BlueCat on 2020/04/13 12:12.
 */
import { isApp, isWeChat } from '@/utils/system'

const wx = require('weixin-js-sdk')

const JS_API_LIST = { jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] }

export default function (signPackage, share) {
  if (isWeChat && signPackage) {
    wx.config({ ...signPackage, ...JS_API_LIST })
    if (share) {
      wx.ready(() => {
        wx.updateAppMessageShareData(share)
        wx.updateTimelineShareData(share)
      })
    }
  }
  isApp && initQianFan(share)
}
function initQianFan (share) {
  if (window.QF) {
    const QFH5 = new window.QF()
    if (share) {
      const { title, image, description, url } = share
      QFH5.setSharable(0)
      QFH5.setShareInfo(title, image, description, url)
    } else {
      QFH5.setSharable(1)
    }
  }
}
